<?php
/**
* @file $Id: TeacherCompletion.php 507 2007-05-11 23:41:24Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

if($_REQUEST['month_date'] && $_REQUEST['day_date'] && $_REQUEST['year_date'])
{
	while(!VerifyDate($date = $_REQUEST['day_date'].'-'.$_REQUEST['month_date'].'-'.$_REQUEST['year_date']))
		$_REQUEST['day_date']--;
}
else
{
	$date = DBDate();
	$_REQUEST['day_date'] = date('d');
	$_REQUEST['month_date'] = date('M');
	$_REQUEST['year_date'] = date('y');
}

$time = mktime(0,0,0,(MonthNWSwitch(substr($date,3,3))*1),(substr($date,0,2)*1),substr($date,7));
$day = date('D',$time);
switch($day)
{
	case 'Sun':
		$day = 'U';
	break;
	case 'Thu':
		$day = 'H';
	break;
	default:
		$day = substr($day,0,1);
	break;
}

$QI = DBQuery("SELECT PERIOD_ID,TITLE FROM SCHOOL_PERIODS WHERE SCHOOL_ID='".UserSchool()."' AND SYEAR='".UserSyear()."' ORDER BY SORT_ORDER ");
$periods_RET = DBGet($QI);

$period_select =  "<SELECT name=period><OPTION value=''>"._('All')."</OPTION>";
foreach($periods_RET as $period)
	$period_select .= "<OPTION value=$period[PERIOD_ID]".(($_REQUEST['period']==$period['PERIOD_ID'])?' SELECTED':'').">".$period['TITLE']."</OPTION>";
$period_select .= "</SELECT>";

DrawHeader(ProgramTitle());
echo "<FORM action=Modules.php?modname=$_REQUEST[modname] method=POST>";
DrawHeader(' &nbsp; &nbsp; <B>'._('Report Date').': </B>'.PrepareDate($date,'_date',false,array('submit'=>true)).' - '.$period_select,'<INPUT type=submit value='._('Go').'>');
echo '</FORM>';

$sql = "SELECT s.LAST_NAME||', '||s.FIRST_NAME AS FULL_NAME,sp.TITLE,cp.PERIOD_ID,s.STAFF_ID 
		FROM USERS s,COURSE_PERIODS cp,SCHOOL_PERIODS sp 
		WHERE 
			sp.PERIOD_ID = cp.PERIOD_ID
			AND cp.TEACHER_ID=s.STAFF_ID AND cp.MARKING_PERIOD_ID IN (".GetAllMP('QTR',GetCurrentMP('QTR',$date)).") 
			AND cp.SYEAR='".UserSyear()."' AND cp.SCHOOL_ID='".UserSchool()."' AND s.PROFILE='teacher'
			AND cp.DOES_ATTENDANCE='Y' AND cp.DAYS LIKE '%".$day."%'"
			.(($_REQUEST['period'])?" AND cp.PERIOD_ID='$_REQUEST[period]'":'')."
			AND NOT EXISTS (SELECT '' FROM ATTENDANCE_COMPLETED ac WHERE ac.STAFF_ID=cp.TEACHER_ID AND ac.SCHOOL_DATE='$date' AND ac.PERIOD_ID=sp.PERIOD_ID)
		";

$RET = DBGet(DBQuery($sql),array(),array('STAFF_ID','PERIOD_ID'));

if(count($RET))
{
	foreach($RET as $staff_id=>$periods)
	{
		$i++;
		$staff_RET[$i]['FULL_NAME'] = $periods[key($periods)][1]['FULL_NAME'];
		foreach($periods as $period_id=>$period)
		{
			$staff_RET[$i][$period_id] = '<IMG SRC=assets/x.gif>';
		}
	}
}

$columns = array('FULL_NAME'=>_('Teacher'));
if(!$_REQUEST['period'])
{
	foreach($periods_RET as $period)
		$columns[$period['PERIOD_ID']] = $period['TITLE'];
}
ListOutput($staff_RET,$columns,_('Teacher who hasn\'t taken attendance'),_('Teachers who haven\'t taken attendance'));

?>